package com.jinmdz.fmis.dao.admin.dao;

import com.jinmdz.fmis.dao.admin.model.timesegment.TimeSegmentEditItem;
import com.jinmdz.fmis.dao.admin.model.timesegment.TimeSegmentListItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;

/**
 * 火化预约时间段维护Dao
 *
 * @author LiCongLu
 * @date 2020-03-12 14:10
 */
public interface TimeSegmentDao {

    /**
     * 按照火化炉类型查询火化预约时间段列表
     *
     * @param furnaceTypeCode 火化炉类型编码
     * @return
     * @author LiCongLu
     * @date 2020-03-12 14:10
     */
    @Select(" select id,furnace_type_code,appointment_time_segment,sort,version " +
            "  from cremation_time_segment where furnace_type_code = #{furnaceTypeCode} and deleted = 0 order by appointment_time_segment")
    ArrayList<TimeSegmentListItem> listTimeSegmentListByCode(@Param("furnaceTypeCode") Integer furnaceTypeCode);

    /**
     * 按照主键获取火化预约时间段信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-12 14:10
     */
    @Select(" select id,furnace_type_code,appointment_time_segment,sort,version " +
            "  from cremation_time_segment where id = #{id} and deleted = 0 limit 1")
    TimeSegmentEditItem getTimeSegmentEditById(@Param("id") Integer id);

    /**
     * 按照火化预约时间段编码查询非当前火化预约时间段信息主键
     *
     * @param appointmentTimeSegment 火化预约时间段编码
     * @param furnaceTypeCode        火化炉类型
     * @return
     * @author LiCongLu
     * @date 2020-03-12 14:10
     */
    @Select(" select id from cremation_time_segment where appointment_time_segment = #{appointmentTimeSegment} and furnace_type_code = #{furnaceTypeCode} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getTimeSegmentIdByTimeSegmentCode(@Param("appointmentTimeSegment") String appointmentTimeSegment, @Param("furnaceTypeCode") Integer furnaceTypeCode);

    /**
     * 按照火化预约时间段编码查询非当前火化预约时间段信息主键
     *
     * @param startTime       火化预约时间段开始时间
     * @param furnaceTypeCode 火化炉类型
     * @return
     * @author LiCongLu
     * @date 2020-04-17 10:45
     */
    @Select(" select id from cremation_time_segment where appointment_time_segment like concat('',#{startTime.},'-%') and furnace_type_code = #{furnaceTypeCode} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getTimeSegmentIdByStartTime(@Param("startTime") String startTime, @Param("furnaceTypeCode") Integer furnaceTypeCode);

    /**
     * 按照火化预约时间段编码查询非当前火化预约时间段信息主键
     *
     * @param endTime         火化预约时间段结束时间
     * @param furnaceTypeCode 火化炉类型
     * @return
     * @author LiCongLu
     * @date 2020-04-17 10:45
     */
    @Select(" select id from cremation_time_segment where appointment_time_segment like concat('%-',#{endTime},'') and furnace_type_code = #{furnaceTypeCode} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getTimeSegmentIdByEndTime(@Param("endTime") String endTime, @Param("furnaceTypeCode") Integer furnaceTypeCode);
}
